<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta content="WangID通城" http-equiv="keywords">
<meta name="description" content="WangID通城">
<meta name="viewport" content="width=device-width,user-scalable=no, initial-scale=1">
<title>WangID通城</title>
<link rel="stylesheet" href="css/index.css" type="text/css">
<link rel="stylesheet" href="css/zy.css" type="text/css">
<link rel="stylesheet" href="css/swiper.min.css" type="text/css">
<script type="text/javascript" src="js/swiper.min.js"></script>
<script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
	<link rel="stylesheet" href="/js/plugins/dialog/dialog.css">
	<script src="/js/common.js"></script>
	<script src="/js/plugins/jquery/jquery.min.js"></script>
	<script src="/js/plugins/dialog/dialog.min.js"></script>


</head>
<body> 
<!--页面内容
<div id="yemnr">--> 
<!--头部--> 
<div class="toub_beij toub_beij_zy">
	<div class="zhongj_k zhongj_k_z">
		<div class="jiu_feo jiu_feo_jifsc">
			<div class="logo_k logo_k_fanh"><a href="javascript:history.go(-1)"><img class="fanh_ann" src="images/web/fanh.png"></a></div>
			<div class="zhongjain_daoh">
				<ul class="jifsc_ul">
					<li><a class="zyyge">购物车</a></li>
					<li style="float: right;"><a href="/shopping/mypoint.html" class="zyyge">我的积分</a></li>
				</ul>
			</div>
		</div>
		<!--<div class="dengl">
			<div class="caid_img" id="zhu_caid">
				&lt;!&ndash;<img src="images/web/cd_1.png">&ndash;&gt;
			</div>
			<ul class="zhu_daoh" id="daoh_lb">
				<em></em>
				<li><a href="index.html">首页</a></li>
				<li><a href="分类.html">商品分类</a></li>
				<li><a href="#">扫一扫</a></li>
				<li><a href="购物车.html">购物车</a></li>
				<li class="wu"><a href="#">我的通城</a></li>
			</ul>
		</div>-->
	</div>
</div>
<script type="text/javascript">
	//滑动头部透明（针对首页头部用）
	window.onscroll=function(){

	var autoheight=document.body.scrollTop||document.documentElement.scrollTop;
	if(autoheight>10){
		$(".toub_beij").css("position" ,"fixed")
		}else{
			$(".toub_beij").css("position" ,"relative")
		}
	}
</script>
<!--内容--> 
<div class="weidl_dl">
	<!--<p>立即登录，同步电脑和手机购物车中的商品 <a href="wanagid_DengLu.html">登录</a></p>-->
</div>
 <div class="gouwuc_kk">
 	<!--<ul>
 		<li>
 			&lt;!&ndash;<div class="dianpmc_gw"><i class="i i-i"></i><a href="#"><p class="px24">鼎力电脑专营旗舰店</p><em></em></a></div>&ndash;&gt;
 			<div class="diannao_shanp">
 				<i class="i1 i1-i"></i>
 				<a href="商品页面.html"><h1><img src="images/web/001.jpg"></h1></a>
 				<div class="you">
 					<a href="商品页面.html"><p class="px24 bt">联想（Lenovo）IdeaPad 710S-13 13.3英寸超极本电脑(i3/....</p></a>
 					<p class="xh">i3/4G内存/128固态/金色</p>
 					<div class="youjfy">
						<div class="goum_sl">
							<p class="px26 jiaq">￥6588.00</p>
							<div class="counter_box">
								<i class="jian">-</i>
								<input type="text" value="1">
								<i class="jia">+</i>
							</div>
						</div>
 					</div>
					<div class="bianj">
						&lt;!&ndash;<a href="#"><p><i></i>移入收藏</p></a>&ndash;&gt;
						<a href="#" class="ayou"><p><i class="sc"></i>删除</p></a>
					</div>
 				</div>
 			</div>
 		</li>
 	</ul>-->
 </div>
<!--底部导航-->
<!---->
<div class="dib_daoh_b">
	<div class="gouwuc_ gouwuc_yem">
		<div class="zuo">
			<i class="i1"><p>全选</p></i> 
		</div>
		<div class="zhong"><p>总计：<em></em> 积分</p></div>
		<div class="you">
			<div class="goum">
				<a >去结算<en></en></a>
			</div>
		</div>
	</div>
</div>
</div>

<!--大框div
</div>-->
<!--搜索页面--> 
</body>
</html>

<script type="text/javascript">

	$(function () {
		// var id = getParams().id;//goodsId
        var user = getUser();
        if (user){
        } else {
            window.location.href = "/login.html";
        }
        var userId = user.id;//userId
        var allPrice = 0;
        // console.log(userId);
        // console.log(id);

		$.get("/users/"+userId+"/carts", function (data) {
			// console.log(data);
			$(data).appendTo(".gouwuc_kk");
			/*$("em.jiaq").each(function (i, n) {
				allPrice = allPrice + parseInt($(n).html().replace(",",""));
			});*/
			// console.log(allPrice);
			cao(allPrice);
		});

        $(".goum a").click(function () {
            var msg ="";
            $(".gouwuc_kk i.i1").each(function (i , n) {
                if ($(n).attr("class").indexOf("i1-i") != -1) {
                    var json = $(n).data("json");
                    var cartId = json.id;
                    if (!msg){
                        msg = msg + "cartId=" +cartId;
					} else {
                        msg = msg + "&" + "cartId=" +cartId;
					}
                }
            });
            $(this).attr("href","/shopping/productAdd.html?"+msg);
        });

		/*$(".goum a").click(function () {
            $(document).dialog({
                type : 'confirm',
                style: 'ios',
                titleText: '提示',
                content: '请再次确认兑换所选商品.',
                buttons: [
                    {
                        name: '取消'
                    },
                    {
                        name: '确认',
                        class: 'dialog-btn-hl',
                        callback: function() {
                            //发请求将购物车状态转成1
							//扣除积分
                            //生成购物信息 //userId && msg ( title  && price )
                            $(".gouwuc_kk i.i1").each(function (i , n) {

                                console.log($(n));
                                if ($(n).attr("class").indexOf("i1-i") != -1) {

                                    var json = $(n).data("json");
                                    console.log(json);
                                    $.ajax({
                                        url: "/carts/"+json.id,
                                        type: "PUT",
                                        data: {state:1},
                                        success: function (result) {
                                            // alert("操作成功!");
                                        }
                                    });

                                    var msg = "兑换"+json.count+"件"+json.goodsTitle+"成功,花费"+json.price+"积分";
									$.ajax({
                                        type: "POST",
                                        url: "/carts/pointmsgs",
                                        data: {"user.id":userId , msg:msg},
                                        success: function (result) {
                                            // alert("操作成功!");
                                        }
									})

                                }
                            });

                            var consume = $(".zhong em").html();
                            $.ajax({
                                url: "/users/"+userId+"/points",
                                type: "PUT",
                                data: {consume:consume},
                                success: function (result) {
                                    // alert("操作成功!");
                                }
                            });

                            location.href = "/shopping/record.html";

                        }
                    }
                ]
            });
        });*/
    });

	function cao(allPrice) {
        $("i.i1").click(function () {
            $(this).toggleClass("i1-i");
            if ($(this).attr("class").indexOf("i1-i") != -1) { // 点击选中

                if ("zuo" == $(this).closest("div").attr("class")) { //点击全选时

                    $("em.jiaq").each(function (i, n) {
                        allPrice = allPrice + parseInt($(n).html().replace(",",""));
                    });
                    $(".gouwuc_kk i.i1").addClass("i1-i");
                } else {
                    var sta = true;
                    $(".gouwuc_kk i.i1").each(function (i , n) {
                        sta = $(n).attr("class").indexOf("i1-i") != -1 && sta;
                    });
                    if (sta) {
                        $(".dib_daoh_b i.i1").addClass("i1-i");
                    }
                    allPrice = allPrice + parseInt($(this).closest("div").find("em").html().replace(",",""));
                }
                $(".zhong em").html(allPrice);
            } else { //点击取消选中

                if ("zuo" == $(this).closest("div").attr("class")) {//点击全选时

                    $("em.jiaq").each(function (i, n) {
                        allPrice = 0;
                    });
                    $(".gouwuc_kk i.i1").removeClass("i1-i");
                } else {
                    var sta = true;
                    $(".gouwuc_kk i.i1").each(function (i , n) {
                        sta = $(n).attr("class").indexOf("i1-i") != -1 && sta;
                    });
                    if (!sta) {
                        $(".dib_daoh_b i.i1").removeClass("i1-i");
                    }
                    allPrice = allPrice - parseInt($(this).closest("div").find("em").html().replace(",",""));
                }
                $(".zhong em").html(allPrice);
            }

        });

        $(".jia").click(function () {
            var price = $(this).closest("div").prev("p").find("em").data("price");
            // console.log(parseInt(allPrice.replace(",","")));
            var count = $(this).prev("input");
            var val = parseInt(count.val());
            var arg = parseInt(price.replace(",",""));
            count.val(val+1);
            var id = count.data("id");
            $(this).closest("div").prev("p").find("em").html(arg*(val+1));
            if ($(this).closest(".diannao_shanp").find("i.i1").attr("class").indexOf("i1-i") != -1){
                allPrice = allPrice + arg;
                $(".zhong em").html(allPrice);
            }
            $.ajax({
				type:"PUT",
				url:"/carts/"+id+"/counts",
				data:{count:count.val() , "goods.price":arg},
				success:function (data) {
                }
			})


        });
        $(".jian").click(function () {
            var price = $(this).closest("div").prev("p").find("em").data("price");
            var count = $(this).next("input");
            var val = parseInt(count.val());
            var id = count.data("id");
            if (val > 1){
                var arg = parseInt(price.replace(",",""));
                count.val(val-1);
                $(this).closest("div").prev("p").find("em").html(arg*(val-1));
                if ($(this).closest(".diannao_shanp").find("i.i1").attr("class").indexOf("i1-i") != -1){
                    allPrice = allPrice - arg;
                    $(".zhong em").html(allPrice);
                }
                $.ajax({
                    type:"PUT",
                    url:"/carts/"+id+"/counts",
                    data:{count:count.val() ,"goods.price":arg},
                    success:function (data) {

                    }
                })
            }
        });
        $(".deleteBtn").click(function () {
            var id = $(this).data("id");
            $.ajax({
                type:"POST",
                url:"/carts/"+id,
                data:{"_method":"DELETE" },
                success:function (data) {
                    window.location.reload();
                }
            });
        });
    }

	window.onload=function(){ 
		var TheMenu=document.getElementById('zhu_caid');
		var LieBiao=document.getElementById('daoh_lb'); 
		var Html=document.getElementsByTagName("html")[0];//0 第一个数组
		TheMenu.onclick=function(event)
		{
			if (LieBiao.style.display=='block')
			{
				LieBiao.style.display='none';
			}
			else {
				LieBiao.style.display='block';
			}  
			event.stopPropagation();//阻止冒泡事件
		} 
		Html.onclick=function(){
			LieBiao.style.display='none';
		}

		// 
		 
 };
 
</script>